﻿using System;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace KingTools.CacheHelper
{
    public class CacheUtils
    {
        /// <summary>
        ///     Execute URL ACCESS
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static bool UrlToExecute(string url, TextBox txtResult)
        {
            try
            {
                var request = (HttpWebRequest) WebRequest.Create(url);
                var response = (HttpWebResponse) request.GetResponse();
                Stream stream = response.GetResponseStream();
                var rsByte = new Byte[response.ContentLength];
                stream.Read(rsByte, 0, (int) response.ContentLength);
                txtResult.Text = Encoding.UTF8.GetString(rsByte, 0, rsByte.Length);
                return true;
            }
            catch (Exception e)
            {
                e.ToString();
            }
            return false;
        }
    }
}